package bdcin.servlet.actions.area;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import bdcin.classesbasicas.Area;
import bdcin.excecoes.BuscarException;
import bdcin.fachada.BDCInFactory;
import bdcin.fachada.IBDCIn;
import bdcin.servlet.actions.Action;

public class CarregarDadosAreaAction extends Action {

	@Override
	public void executar(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		
		String nomeJSP = request.getParameter("nomeJSP");
		
		IBDCIn facade = BDCInFactory.getFacade();
		
		long id = Long.parseLong(request.getParameter("id"));
		
		Area area = null;
		try {
			area = facade.buscarArea(id);
		} catch (BuscarException e) {
			request.setAttribute("mensagem", e.getMessage());
			request.getRequestDispatcher("mensagem.jsp");
		}  
		
		request.setAttribute("area",area );
		
		
		nomeJSP = "/area/" + nomeJSP + ".jsp";
		
		
		
		request.getRequestDispatcher(nomeJSP).forward(request, response);

	}

}
